#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys
import time
import datetime
import commands

def process_hour(hour):
    cmd = "python process.py {0}00".format(iter_str)
    print cmd
    ret = commands.getstatusoutput(cmd)
    if ret[0] == 0:
        print "{0} success".format(iter_str)
    else:
        print "return problem {0}".format(ret)


def day_loop():
    if len(sys.argv) < 3:
        print 'argument is less then 3'
        print 'Usage:{} 2022-01-01 2022-01-03'.format(sys.argv[0])
        exit(1)

    time_format = '%Y-%m-%d'
    time_start = sys.argv[1]
    time_end = sys.argv[2]

    if (int(time_start.replace('-', '')) > int(time_end.replace('-', ''))):
        exit(1)

    input_hour_time = time.strptime(time_start, time_format)
    #如果要进行不同时间度量的修改，这里需要修改  day:3  hour:4
    base_hour = datetime.datetime(*input_hour_time[:3])

    iter_hour = base_hour
    while True:
        iter_str = iter_hour.strftime(time_format)

        if iter_str == time_end:
            print "loop end"
            break
        print iter_str
        iter_hour = iter_hour + datetime.timedelta(days=1)


def hour_loop():
    if len(sys.argv) < 3:
        print 'argument is less then 3'
        print 'Usage:{} 2022010100 2022010103'.format(sys.argv[0])
        exit(1)

    time_format = '%Y%m%d%H'
    time_start = sys.argv[1]
    time_end = sys.argv[2]

    if (int(time_start.replace('-', '')) > int(time_end.replace('-', ''))):
        exit(1)

    input_hour_time = time.strptime(time_start, time_format)
    #如果要进行不同时间度量的修改，这里需要修改  day:3  hour:4
    base_hour = datetime.datetime(*input_hour_time[:4])

    iter_hour = base_hour
    while True:
        iter_str = iter_hour.strftime(time_format)

        if iter_str == time_end:
            print "loop end"
            break
        print iter_str
        #exec program
        process_hour(iter_str)
        iter_hour = iter_hour + datetime.timedelta(hours=1)

if __name__ == '__main__':
    hour_loop()

